#!usr/bin/python3
#用于classify合并，新分类的train和test移动到老版分类的train和test中
import sys
import getopt
import os
import shutil

def getFilePathFromDir(path, suffixes):
    """
    获取该目录下的所有文件完整路径，不递归
    :param path:
    :return:
    """
    L = []
    for dirpath, dirnames, filenames in os.walk(path):
        for item in filenames:
            if item[0] == ".":
                continue
            if os.path.splitext(item)[1] in suffixes:
                L.append(os.path.join(dirpath, item))
        return L

def getDirNameFromDir(path):
    """
    获取该目录下的所有一级子目录的目录名，不递归
    :param path:
    :return:
    """
    L = []
    for dirpath, dirnames, filenames in os.walk(path):
        return dirnames

def main(argv):
    dec = """用于classify合并，新分类的train和test移动到老版分类的train和test中
    """
    suffixes = ['.png','.jpeg','.jpg','.xml']
    newClassPath = argv[0]  # 新分类的
    oldClassPath = argv[1]  # 老板分类路径
    newClassList = getDirNameFromDir(newClassPath)
    for item in newClassList:
        currentNewTrainPath = newClassPath + "/" + item + "/train"
        currentNewTestPath = newClassPath + "/" + item + "/test"
        currentOldTrainPath = oldClassPath + "/" + item + "/train"
        currentOldTestPath = oldClassPath + "/" + item + "/test"
        newTestList = getFilePathFromDir(currentNewTestPath, suffixes)
        newTrainList = getFilePathFromDir(currentNewTrainPath, suffixes)
        for f in newTestList:
            shutil.copy(f,currentOldTestPath)
            # print("{} ----> {}".format(f,currentOldTestPath))
        for f in newTrainList:
            shutil.copy(f,currentOldTrainPath)
            print("{} ----> {}".format(f,currentOldTrainPath))


if __name__ == "__main__":
    main(sys.argv[1:])
